/*
 * Anhlx Create Validate
 */

function checkValidate(id_append){
    var emailRegex = /^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,6}$/i,
    numericRegex = /^[0-9-]+$/;
    // error msg depends on the language
    var errormsg = new Array();
    errormsg[1] = 'The %s field is required.';
    errormsg[2] = 'Please input your %s';
    errormsg[3] = 'The %s field must contain only numbers.';
    errormsg[4] = 'This %s address is invalid.';
    errormsg[5] = '%s is too short. %s must be at least %number characters';
    errormsg[6] = 'Confirm password does not match password';
    errormsg[7] = 'The %s field must not exceed %number characters in length.';
    errormsg[8] = 'This %s is invalid.';
    //show msg
    var msgEr = '';
    var valueStr = '';
    var num_milliseconds= 3000;
    //check
      if($('input[name="email"]').val() == '' || $('input[name="email"]').val() == 'E-mail') {
        msgEr = errormsg[2].replace('%s', 'email');
        $('#'+id_append+'').addClass('active').children().html(msgEr);
        hideError(id_append,$('input[name="email"]'),num_milliseconds);
        return false;
    }else if($('input[name="email"]').val() != '' ){
        valueStr = $('input[name="email"]').val();
        if (!emailRegex.test(valueStr)) {
            msgEr = errormsg[4].replace('%s', 'email');
            $('#'+id_append+'').addClass('active').children().html(msgEr);
            hideError(id_append,$('input[name="email"]'),num_milliseconds);
            return false;
        }  
    }
    
    if ($('input[name="password"]').val() == '' || $('input[name="password"]').val() == 'Password') {
        msgEr = errormsg[2].replace('%s', 'password');
        $('#'+id_append+'').addClass('active').children().html(msgEr);
        hideError(id_append,$('input[name="password"]'),num_milliseconds);
        return false;
    } 
    
    return true;
}

function hideError(id_append,item,num_milliseconds){
    item.css("color","red");
    setTimeout(function() {
        $('#'+id_append+'').fadeOut('fast',function(){
//            $('#'+id_append+'').show();
        });
        $('#'+id_append+'').removeClass('active').children().html('');
    }, num_milliseconds);
}

$(function(){    
    $('#login-password').focus(function() {
        $(this).val('').prop('type', 'password');
    })
    .blur(function() {
        if($(this).val() == '') {
            $(this).val($(this).attr('rel')).prop('type', 'text');
        }
    });
    
    $('input[type="text"]').focus(function(){
        $(this).css("color","#A9AAAB");
        if (this.value == "E-mail"){
            this.value = '';
        }
        if(this.value != "E-mail"){
            this.select();
        }
    }).blur(function(){
        if (jQuery.trim(this.value) == ''){
            this.value = (this.defaultValue ? this.defaultValue : '');
        }
    });

    $('#check_remember').click(function(){

        if($('#check_remember').attr('checked')) {
            $('#check_remember').parent().removeClass("div_check_remember");
            $('#check_remember').parent().addClass("div_check_remember_checked");
        } else {
            $('#check_remember').parent().removeClass("div_check_remember_checked");
            $('#check_remember').parent().addClass("div_check_remember");
        }

    });
    

});





